// 验证管理员用户是否已登录
export default defineEventHandler(async (event) => {
	// 排除的路由
	const excludePaths = ['/api/admin/user/login'];

	if (event.path.includes('/admin/') && !excludePaths.includes(event.path)) {
		try {
			const loginStatus = await adminIsLogin(event);

			if (!loginStatus) {
				return {
					code: 0,
					message: '请先登录',
				};
			}
			event.context.user = loginStatus.user;
		} catch (err: any) {
			error(err);
			return {
				code: 0,
				message: err.message,
			};
		}
	}
});
